package solution.tree.arraytransfer;

public class TransferOps {
    private TNode root;

    public TNode getRoot() {
        return root;
    }

    public void setRoot(TNode root) {
        this.root = root;
    }

    public void transfer(int[] array) {
        int rootIndex = array.length % 2 == 1 ? array.length / 2 : array.length / 2 - 1;
        root.no = array[rootIndex]; //root节点
        setRoot(root);
        for (int i = 0 ; i < array.length ; i++){
            if (i < rootIndex){
                root.left.no = array[i];
                root.right.no = array[i++];
                i++;
                int[] trans = new int[rootIndex - i];
                for (int j = 0 ; j < rootIndex ; j++){
                    trans[j] = array[j];
                }
                transfer(trans);
            }else {

            }
        }

    }
}
